package com.ruoyi.law.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.law.domain.dto.LawNewsDTO;
import com.ruoyi.law.domain.entity.LawNews;
import com.ruoyi.law.mapper.LawNewsMapper;
import com.ruoyi.law.service.ILawNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 新闻 服务实现类
 * </p>
 *
 * @author code
 * @since 2022-12-11
 */
@Service
public class LawNewsServiceImpl extends ServiceImpl<LawNewsMapper, LawNews> implements ILawNewsService {

    @Autowired
    private LawNewsMapper lawNewsMapper;

    @Override
    public Page<LawNewsDTO> myPage(Page<LawNews> page) {
        return lawNewsMapper.myPage(page);
    }

    @Override
    public List<LawNewsDTO> getBytypeId(Long typeId) {
        LambdaQueryWrapper<LawNews> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(LawNews::getType, typeId);
        queryWrapper.orderByAsc(LawNews::getSort);
        List<LawNews> list = super.list(queryWrapper);
        return BeanUtil.copyToList(list, LawNewsDTO.class);
    }
}
